package com.tianya.controller;

import com.tianya.common.Results;
import com.tianya.domain.entity.Schedule;
import com.tianya.domain.vo.ScheduleVO;
import com.tianya.service.ScheduleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author TianYaGuoKe
 * @date 2025/5/27 9:43
 * @description ScheduleController
 */
@Api("课表管理")
@RestController
@RequestMapping("/schedule")
public class ScheduleController {
    @Resource
    private ScheduleService scheduleService;

    @ApiOperation("根据班级ID查询")
    @GetMapping("/{id}")
    public Results<List<ScheduleVO>> getScheduleByClazzId(@PathVariable Long id) {
        return Results.success(scheduleService.getScheduleByClazzId(id));
    }

    @ApiOperation("根据学生id")
    @GetMapping("/student/{id}")
    public Results<List<Schedule>> list(@PathVariable Long id) {
        return Results.success(scheduleService.getScheduleByStudentId(id));
    }


    @ApiOperation("根据教师id查询课表")
    @GetMapping("/teacher/{id}")
    public Results<List<Schedule>> listByTeacherId(@PathVariable Long id) {
        return Results.success(scheduleService.listByTeacherId(id));
    }

    @ApiOperation("创建课表")
    @PostMapping
    public Results createSchedule(@RequestBody Schedule schedule) {
        scheduleService.save(schedule);
        return Results.success();
    }

    @ApiOperation("更新课表")
    @PutMapping
    public Results updateSchedule(@RequestBody Schedule schedule) {
        scheduleService.updateById(schedule);
        return Results.success();
    }

    @ApiOperation("删除课表")
    @DeleteMapping("/{id}")
    public Results deleteSchedule(@PathVariable Long id) {
        scheduleService.removeById(id);
        return Results.success();
    }
}
